function [AllData, TrueLabel, AllDataSampler, AllDataTraining, TrueLabelTraining, AllDataTesting, TrueLabelTesting, SampledTrueLabelTraining, SampledOnlyDataTraining, SampledOnlyTrueLabelTraining, UnsampledOnlyDataTraining, DataSampler, SampledDataSize, SampledLabelSize] = Ddavid_Incomplete_Label_Preprocessing(Incomplete_Label_Preprocessing_Option, varargin)

% [AllData, TrueLabel, AllDataSampler, AllDataTraining, TrueLabelTraining,
%   AllDataTesting, TrueLabelTesting, SampledTrueLabelTraining,
%   SampledOnlyDataTraining, SampledOnlyTrueLabelTraining,
%   UnsampledOnlyDataTraining, DataSampler, SampledDataSize,
%   SampledLabelSize]
% = Ddavid_Incomplete_Label_Preprocessing(
%   Incomplete_Label_Preprocessing_Option, AllData, TrueLabel)
% 
% [AllData, TrueLabel, AllDataSampler, AllDataTraining, TrueLabelTraining,
%   AllDataTesting, TrueLabelTesting, SampledTrueLabelTraining,
%   SampledOnlyDataTraining, SampledOnlyTrueLabelTraining,
%   UnsampledOnlyDataTraining, DataSampler, SampledDataSize,
%   SampledLabelSize]
% = Ddavid_Incomplete_Label_Preprocessing(
%   Incomplete_Label_Preprocessing_Option, AllData, TrueLabel,
%   AllDataSampler)
% 
% [AllData, TrueLabel, AllDataSampler, AllDataTraining, TrueLabelTraining,
%   AllDataTesting, TrueLabelTesting, SampledTrueLabelTraining,
%   SampledOnlyDataTraining, SampledOnlyTrueLabelTraining,
%   UnsampledOnlyDataTraining, DataSampler, SampledDataSize,
%   SampledLabelSize]
% = Ddavid_Incomplete_Label_Preprocessing(
%   Incomplete_Label_Preprocessing_Option, AllDataTraining,
%   TrueLabelTraining, AllDataTesting, TrueLabelTesting)

switch nargin
    case 3
        disp('Given AllData, TrueLabel, create DataSampler and do cross validation');
        AllData = varargin{1};
        TrueLabel = varargin{2};
    case 4
        disp('Given AllData, TrueLabel, DataSampler, do cross validation');
        AllData = varargin{1};
        TrueLabel = varargin{2};
        AllDataSampler = varargin{3};
    case 5
        disp('Given AllDataTraining, TrueLabelTraining, AllDataTesting, TrueLabelTesting');
        AllDataTraining = varargin{1};
        TrueLabelTraining = varargin{2};
        AllDataTesting = varargin{3};
        TrueLabelTesting = varargin{4};
        AllDataSampler = [];
end

% Preprocessing steps
% 0.  If there are AllDataTraining and AllDataTesting, no AllData
%     AllDataTraining + AllDataTesting -> AllData
% 1.  Cross validation
%     AllData -> AllData + AllDataSampler
% 2.  Pick a fold
%     AllData + AllDataSampler -> AllDataTraining + AllDataTesting
%     TrueLabel + AllDataSampler -> TrueLabelTraining + TrueLabelTesting
% 3.  Sample incomplete labels
%     TrueLabelTraining -> SampledTrueLabelTraining
%     AllDataTraining -> SampledOnlyDataTraining
%     TrueLabelTraining -> SampledOnlyTrueLabelTraining
% 4.  Use
%     Full:
%       AllDataTraining + TrueLabelTraining
%     Incomplete labeled data + unlabeled data:
%       AllDataTraining + SampledTrueLabelTraining
%     Only incomplete labeled data:
%       SampledOnlyDataTraining + SampledOnlyTrueLabelTraining

% 0.  If there are AllDataTraining and AllDataTesting, no AllData
if(nargin == 5)
    AllData = [AllDataTraining; AllDataTesting];
    TrueLabel = [TrueLabelTraining; TrueLabelTesting];
end

% 1.  Cross validation
if(nargin == 3)
    [AllDataSampler] = Ddavid_cross_validation_training_testing(AllData, Incomplete_Label_Preprocessing_Option.TotalFoldNumber);
end

% 2.  Pick a fold
if(nargin == 3 || nargin == 4)
    [AllDataTraining, AllDataTesting, TrueLabelTraining, TrueLabelTesting] = Ddavid_pick_up_fold(AllData, TrueLabel, AllDataSampler, Incomplete_Label_Preprocessing_Option.UsedFoldNumber);
end

% 3.  Sample incomplete labels
[SampledTrueLabelTraining, SampledOnlyDataTraining, SampledOnlyTrueLabelTraining, UnsampledOnlyDataTraining, DataSampler, SampledDataSize, SampledLabelSize] = Ddavid_sample_label(AllDataTraining, TrueLabelTraining, Incomplete_Label_Preprocessing_Option.SampledDataPercent, Incomplete_Label_Preprocessing_Option.SampledLabelPercent);

% 4.  Save
save([Incomplete_Label_Preprocessing_Option.Name '_' int2str(Incomplete_Label_Preprocessing_Option.SampledDataPercent) '_' int2str(Incomplete_Label_Preprocessing_Option.SampledLabelPercent) '_Fold' int2str(Incomplete_Label_Preprocessing_Option.UsedFoldNumber)], 'AllData', 'TrueLabel', 'AllDataSampler', 'AllDataTraining', 'TrueLabelTraining', 'AllDataTesting', 'TrueLabelTesting', 'SampledTrueLabelTraining', 'SampledOnlyDataTraining', 'SampledOnlyTrueLabelTraining', 'UnsampledOnlyDataTraining', 'DataSampler', 'SampledDataSize', 'SampledLabelSize', 'Incomplete_Label_Preprocessing_Option');
